package com.googlecode.wmlynar.gwtbeans.client.ui;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import com.google.gwt.dom.client.Element;
import com.googlecode.wmlynar.gwtbeans.client.beans.SourcesPropertyChangeEvents;

/**
 * Wrapper for TextBox class that posts property change events.
 * 
 * @author Wojciech Mlynarczyk (wmlynar@gmail.com)
 * 
 */
public class Label extends com.google.gwt.user.client.ui.Label implements
        SourcesPropertyChangeEvents {

    PropertyChangeSupport support = new PropertyChangeSupport(this);

    private boolean modifiedByUser;

    public Label() {
        super();
    }

    public Label(final Element element) {
        super(element);
    }

    public Label(final String text, final boolean wordWrap) {
        super(text, wordWrap);
    }

    public Label(final String text) {
        super(text);
    }

    public void setText(final String text) {
        final String old = getText();
        super.setText(text);
        if (support != null) {
            support.firePropertyChange("text", old, text);
        }
    }

    public void addPropertyChangeListener(final String propertyName,
            final PropertyChangeListener listener) {
        support.addPropertyChangeListener(propertyName, listener);
    }

    public void removePropertyChangeListener(final String propertyName,
            final PropertyChangeListener listener) {
        support.removePropertyChangeListener(propertyName, listener);
    }

    public void setModifiedByUser(final boolean modifiedByUser) {
        if (this.modifiedByUser != modifiedByUser) {
            support.firePropertyChange("modifiedByUser", this.modifiedByUser,
                    this.modifiedByUser = modifiedByUser);
        }
    }

    public boolean isModifiedByUser() {
        return modifiedByUser;
    }
}
